package interfaces;
/**
 * @author  Jennifer Henry
 */

import interfaces.admin.FrameAdmin;
import interfaces.rechercheiti.FrameUser;

import java.awt.Component;
import java.awt.event.*;
import javax.swing.*;

import donnees.Donnees;

public class FrameAccueil extends javax.swing.JFrame {

	protected JButton boutonAdmin;
    protected FrameAdmin frameAdmin;
    protected boolean frameAdminOpen;
    protected JButton boutonUser;
    protected FrameUser frameUser;
    protected boolean frameUserOpen;

    /** Creates new form FrameAccueil */
    public FrameAccueil(Donnees dAdmin, Donnees dUser) {
    	initComponents(dAdmin, dUser);
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     */
    private void initComponents(Donnees dAdmin, Donnees dUser) {
        boutonAdmin = new JButton();
        frameAdmin = new FrameAdmin(this, dAdmin);
        frameAdminOpen = false;
        
        boutonUser = new JButton();
        frameUser = new FrameUser(this, dUser);
        frameUserOpen = false;

        //TODO frameAdmin.getModel().addObserverRoute(frameUser.getPanelAffichage());
        //frameAdmin.getModel().addObserverTroncon(frameUser.getPanelAffichage());
        //frameAdmin.getModel().addObserverVille(frameUser.getPanelAffichage());
        
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        setTitle("Accueil");
        
        boutonAdmin.setText("Administrateur");
        boutonAdmin.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
            	frameAdminOpen = true;
            	frameAdmin.open();
            }
        });

        boutonUser.setText("Utilisateur");
        boutonUser.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
            	frameUserOpen = true;
            	frameUser.open();
            }
        });

        GroupLayout layout = new GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(150, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                    .addComponent(boutonAdmin)
                    .addComponent(boutonUser, GroupLayout.PREFERRED_SIZE, 101, GroupLayout.PREFERRED_SIZE))
                .addGap(147, 147, 147))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(82, 82, 82)
                .addComponent(boutonUser, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
                .addGap(26, 26, 26)
                .addComponent(boutonAdmin, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
                .addContainerGap(92, Short.MAX_VALUE))
        );
        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new Component[] {boutonUser, boutonAdmin});
        pack();
    }

	public boolean isFrameUserOpen() {
		return frameUserOpen;
	}

	public void setFrameUserOpen(boolean _frameUserOpen) {
		frameUserOpen = _frameUserOpen;
	}

	public boolean isFrameAdminOpen() {
		return frameAdminOpen;
	}

	public void setFrameAdminOpen(boolean _frameAdminOpen) {
		frameAdminOpen = _frameAdminOpen;
	}

}